import type {
  DragDropManager,
  SourceType,
  XYCoord,
} from '../../classes/interface';
import type { DropTargetMonitor } from '../dropInterface';

class DropTargetMonitorImpl implements DropTargetMonitor {
  private handlerId: string = '';
  private manager: DragDropManager;
  public constructor(manager: DragDropManager) {
    this.manager = manager;
  }

  public receiveHandlerId(newHandlerId: string) {
    if (this.handlerId === newHandlerId) {
      return;
    }

    this.handlerId = newHandlerId;
  }

  public subscribeStateChange: (listenerFn: () => void) => void = (
    listenerFn,
  ) => {
    this.manager.subscribeStateChange(listenerFn);
  };

  public getItem(): any {
    return this.manager.getDragItem();
  }

  public updateItem(newItem: any) {
    this.manager.updateDragItem(newItem);
  }

  public getDragType(): SourceType {
    return this.manager.getDragType();
  }

  public getClientOffset(): XYCoord | undefined {
    return this.manager.getDropEventClientOffset();
  }

  public getDropNodeClientOffset(): XYCoord | undefined {
    return this.manager.getDropNodeClientOffset();
  }

  public getDragStartNodeClientOffset(): XYCoord | undefined {
    return this.manager.getDragStartNodeClientOffset();
  }

  public getDragStartEventClientOffset(): XYCoord | undefined {
    return this.manager.getDragStartEventClientOffset();
  }

  public canDrop(): boolean {
    return this.manager.canDropOnTarget(this.handlerId);
  }

  public isOver(): boolean {
    return this.manager.isOverTarget(this.handlerId);
  }
}

export default DropTargetMonitorImpl;
